package com.hk.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hk.constant.HttpStatus;
import com.hk.core.roleResult.PageRoleResult;
import com.hk.domain.OperLog;
import com.hk.dto.LogDto;
import com.hk.mapper.LogMapper;
import com.hk.service.LogService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl extends ServiceImpl<LogMapper, OperLog> implements LogService {
    @Override
    public PageRoleResult listLog(LogDto logDto) {
        Page<OperLog> page = new Page<>(logDto.getPageNum(), logDto.getPageSize());
        LambdaQueryWrapper<OperLog> wrapper = new LambdaQueryWrapper<>();
        if (ObjectUtils.isNotNull(logDto.getParams().get("beginTime"))){
            wrapper.between(OperLog::getOperTime, logDto.getParams().get("beginTime"), logDto.getParams().get("endTime"));
        }
        wrapper.eq(OperLog::getStatus, 0);
        page = super.page(page, wrapper);
        PageRoleResult result = new PageRoleResult();
        result.setCode(HttpStatus.SUCCESS);
        result.setMsg("查询成功");
        result.setTotal((int) page.getTotal());
        result.setRows(page.getRecords());

        return result;

    }
}
